package com.company.Thread.Concurrent;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class lockMap {
    public static void main(String[] args) {
        /*
        Map<String, String> map = new HashMap<>();
        java.util.ConcurrentModificationException
         */
        /*
        解决方案：
        1、Map<String, String> map = new ConcurrentHashMap<>();

         */
        Map<String, String> map = new ConcurrentHashMap<>();

        for (int i = 0; i < 20; i++) {
            new Thread(()->{
                map.put(Thread.currentThread().getName(), "test");
                System.out.println(map);
            }, String.valueOf(i)).start();
        }
    }
}
